define(["jquery", "bootstrap", "backend", "table", "form"], function ($, undefined, Backend, Table, Form) {
  var Controller = {
    index: function () {
      // 初始化表格参数配置
      Table.api.init({
        extend: {
          index_url: "fssy/areasensitivity/index" + location.search,
          add_url: "fssy/areasensitivity/add",
          edit_url: "fssy/areasensitivity/edit",
          del_url: "fssy/areasensitivity/del",
          multi_url: "fssy/areasensitivity/multi",
          import_url: "fssy/areasensitivity/import",
          table: "fssy_areasensitivity",
        },
      });

      var table = $("#table");

      // 初始化表格
      table.bootstrapTable({
        url: $.fn.bootstrapTable.defaults.extend.index_url,
        pk: "id",
        sortName: "id",
        fixedColumns: true,
        fixedRightNumber: 1,
        searchFormVisible: true, // 是否始终显示搜索表单
        columns: [
          [
            { checkbox: true },
            { field: "id", title: __("Id"), sortable: true },
            { field: "department.department", title: __("Department_id"), formatter: Table.api.formatter.label },
            {
              field: "operator",
              title: __("Operator"),
              operate: "LIKE",
              cellStyle: function (value, row, index) {
                return { css: { color: "#FF790D", "font-weight": "bold" } };
              },
            },
            { field: "actual_bed_days", title: __("Actual_bed_days") },
            { field: "new_admissions_count", title: __("New_admissions_count") },
            { field: "day_shift_nurses", title: __("Day_shift_nurses") },
            { field: "day_shift_patients", title: __("Day_shift_patients") },
            { field: "night_shift_nurses", title: __("Night_shift_nurses") },
            { field: "night_shift_patients", title: __("Night_shift_patients") },
            { field: "nurse_work_hours", title: __("Nurse_work_hours") },
            { field: "catheter_days", title: __("Catheter_days") },
            { field: "astro_tube_days", title: __("Astro_tube_days") },
            { field: "trachea_tube_days", title: __("Trachea_tube_days") },
            { field: "cvc_days", title: __("Cvc_days") },
            { field: "picc_days", title: __("Picc_days") },
            { field: "restraint_days", title: __("Restraint_days") },
            { field: "special_care_bed_days", title: __("Special_care_bed_days") },
            { field: "level_1_bed_days", title: __("Level_1_bed_days") },
            { field: "level_2_bed_days", title: __("Level_2_bed_days") },
            { field: "level_3_bed_days", title: __("Level_3_bed_days") },
            {
              field: "createtime",
              title: __("Createtime"),
              operate: "RANGE",
              addclass: "datetimerange",
              autocomplete: false,
              formatter: Table.api.formatter.datetime,
            },
            {
              field: "updatetime",
              title: __("Updatetime"),
              operate: "RANGE",
              addclass: "datetimerange",
              autocomplete: false,
              formatter: Table.api.formatter.datetime,
              sortable: true,
            },
            { field: "operate", title: __("Operate"), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate },
          ],
        ],
      });

      // 为表格绑定事件
      Table.api.bindevent(table);
    },

    add: function () {
      $(document).ready(function () {
        // console.log("#c-operator = ", $("#c-operator")); // 检查是否存在
        // // 添加时获取当前用户名 赋值给'操作员' =>  Add
        // $.ajax({
        //   url: "/TcQozAZEFm.php/fssy/specialdisease/currentUser",
        //   method: "GET",
        //   success: function (data) {
        //     console.log("成功 = ", data);
        //     $("#c-operator").val(data.user);
        //   },
        //   error: function (xhr, status, error) {
        //     console.error("Error:", error);
        //   },
        // });
      });

      Controller.api.bindevent();
    },

    edit: function () {
      Controller.api.bindevent();
    },

    api: {
      bindevent: function () {
        Form.api.bindevent($("form[role=form]"));
      },
    },
  };
  return Controller;
});
